﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tilver.Coder.Core;

namespace Tilver.Coder.Win.Dialogs
{
    public partial class CreateDataBaseDialog : Form
    {
        /// <summary>
        /// 数据库信息
        /// </summary>
        public CoderDataBase DataBase { get; set; }


        public CreateDataBaseDialog()
        {
            InitializeComponent();

            #region 初始化数据
            cmbDataProvider.DataSource = Enum.GetValues(typeof(DataProviderTypeEnum));
            cmbDataProvider.SelectedItem = DataProviderTypeEnum.MSSQL;
            #endregion
        }

        #region 生成数据数据库连接串
        
        private void btnCreateConnectionString_Click(object sender, EventArgs e)
        {
            var dialog = new DBConnectionDialog();
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtConnectionString.Text = dialog.ConnectionString;
            }
        }
        #endregion


        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtConnectionString.Text.Trim().Length == 0)
            {
                errorProvider_Project.SetError(txtConnectionString, "连接字符串不能为空");
                return;
            }
            DataBase = new CoderDataBase
                {
                    ConnectionString = txtConnectionString.Text,
                    DataProviderType = (DataProviderTypeEnum) cmbDataProvider.SelectedItem
                };
            DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
